package com.example.dnfgamercommunitybackend.entity;

import com.alibaba.fastjson.JSONObject;

public class ResponseResult<T> {
    private int code;
    private String message;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private ResponseResult(int code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> String successStringResult(String message,T data){
        return JSONObject.toJSONString(success(message,data));
    }

    public static <T> String successStringResult(String message){
        return JSONObject.toJSONString(success(message));
    }

    public static <T> String failureStringResult(int code,String message){
        return JSONObject.toJSONString(failure(code,message));
    }

    public static <T> String failureStringResult(String message){
        return JSONObject.toJSONString(failure(message));
    }

    public  static <T> ResponseResult<T> success(String message, T data){
        return new ResponseResult<T>(200,message,data);
    }

    public static <T> ResponseResult<T> success(String message){
        return new ResponseResult<T>(200,message,null);
    }

    public static <T> ResponseResult<T> failure(int code,String message){
        return new ResponseResult<T>(code,message,null);
    }

    public static <T> ResponseResult<T> failure(String message){
        return new ResponseResult<T>(500,message,null);
    }

}
